/**
 * @file hdl_log.c
 * @author your name (you@domain.com)
 * @brief
 * @version 0.1
 * @date 2023-11-20
 *
 * @copyright Copyright (c) 2023
 *
 */
#include "hdl_log.h"

/**
 * @brief 程序日志打印GPIO引脚的初始化
 * @note PB10 PB11
 *
 */
static void prvhdl_log_pin_init(void)
{
    GPIO_InitTypeDef xhdl_pin_struct;

    RCC_AHB1PeriphClockCmd(logUSART_GPIO_CLK, ENABLE);

    GPIO_PinAFConfig(logUSART_GPIO_PORT, logUSART_GPIO_TX_SRC, logUSART_AF);
    GPIO_PinAFConfig(logUSART_GPIO_PORT, logUSART_GPIO_RX_SRC, logUSART_AF);

    xhdl_pin_struct.GPIO_Pin = logUSART_GPIO_TX | logUSART_GPIO_RX;
    xhdl_pin_struct.GPIO_Mode = GPIO_Mode_AF;
    xhdl_pin_struct.GPIO_OType = GPIO_OType_PP;
    xhdl_pin_struct.GPIO_PuPd = GPIO_PuPd_UP;
    xhdl_pin_struct.GPIO_Speed = GPIO_Speed_100MHz;
    GPIO_Init(logUSART_GPIO_PORT, &xhdl_pin_struct);
}

/**
 * @brief 程序日志打印USART初始化
 *
 */
static void prv_hdl_log_usart_init(void)
{
    USART_InitTypeDef xhdl_usart_struct;

    logUSART_CLK_CMD(logUSART_CLK, ENABLE);

    USART_DeInit(logUSARTx);

    xhdl_usart_struct.USART_BaudRate = logBAUDRATE;
    xhdl_usart_struct.USART_Mode = USART_Mode_Tx;
    xhdl_usart_struct.USART_WordLength = USART_WordLength_8b;
    xhdl_usart_struct.USART_Parity = USART_Parity_No;
    xhdl_usart_struct.USART_StopBits = USART_StopBits_1;
    xhdl_usart_struct.USART_HardwareFlowControl = USART_HardwareFlowControl_None;
    USART_Init(logUSARTx, &xhdl_usart_struct);

    USART_Cmd(logUSARTx, ENABLE);
}

/**
 * @brief 程序日志初始化
 *
 */
void vhdl_log_init(void)
{
    prvhdl_log_pin_init();

    prv_hdl_log_usart_init();
}
